package com.example.myapplication.service;

import android.app.IntentService;
import android.content.Intent;
import android.content.Context;
import android.util.Log;

public class MyIntentService extends IntentService {

    public MyIntentService(){super("MyIntentService");}

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i("test", "--------------onHandleIntent");
        if (intent != null) {
           String num = (String) intent.getExtras().get("num");
           if("1".endsWith(num)){

               Log.i("test", Thread.currentThread().getName()+"title:0"+num);

               for(int i =1;i<=5;i++){
                   try {
                       Thread.sleep(1000);
                       Log.i("test", Thread.currentThread().getName()+"----------"+i);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
           }else if("2".endsWith(num)){

               Log.i("test", Thread.currentThread().getName()+"title:1"+num);

               for(int i =10;i<=20;i++){
                   Log.i("test", Thread.currentThread().getName()+"***********"+i);
               }
           }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("test", "服务停止，注销");
    }
}